#include "mq_connection.hpp"

int main()
{
    // 1.实例化异步工作对象
    bitmq::AsyncWorker::ptr awp = std::make_shared<bitmq::AsyncWorker>();
    // 2.实例化连接对象
    bitmq::Connection::ptr conn = std::make_shared<bitmq::Connection>("127.0.0.1", 8085, awp);
    // 3.通过连接创建信道
    bitmq::Channel::ptr channel = conn->openChannel();
    // 4.使用信道提供的服务
    //   1.声明一个交换机
    google::protobuf::Map<std::string, std::string> tmp_map;
    channel->declareExchange("exchange1", bitmq::ExchangeType::DIRECT, true, false, tmp_map);
    //  2.声明一个队列queue1
    channel->declareQueue("queue1", true, false, false, tmp_map);
    //  3.声明一个队列queue2
    channel->declareQueue("queue2", true, false, false, tmp_map);
    //  4.绑定
    channel->queueBind("exchange1", "queue1", "queue1");
    channel->queueBind("exchange1", "queue2", "news.music.#");

    bitmq::BasicProperties bp;

    // 5.循环先交换机发布消息
    for (int i = 0; i < 10; i++)
    {
        bp.set_id(bitmq::UUIDHelper::uuid());
        bp.set_delivery_mode(bitmq::DeliveryMode::DURABLE);
        bp.set_routing_key("queue1");
        channel->basicPublish("exchange1", &bp, "Hello World-" + std::to_string(i));
    }

    // 6.关闭信道
    channel->closeChannel();
    // 7.关闭连接
    return 0;
}